package model.eval;

import enums.PremisaTypeEnum;
import enums.TestPanelEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import misc.BundlesProvider;
import model.Sylogism;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Jose Martin Rozanec;
 */
public class TestExerciseAnalyzeSylogism extends TestExcercise {

    /**
     * Constructor;
     */
    public TestExerciseAnalyzeSylogism() {
        this.panelEnum = TestPanelEnum.ANALISIS_SILOGISMO;
    }

    public int getAchievedScore() {
        SylogismData data = (SylogismData) getStudentsSolution();
        Sylogism sylogism = (Sylogism) getExcerciseData();
        boolean correct = true;

        if (data.getTerminoMayor() != null && data.getTerminoMedio() != null && data.getTerminoMenor() != null &&
                data.getPremisaMayorExtension() != null && data.getTerminoMedio() != null &&
                data.getTerminoMenor() != null && data.getFigura() != null) {

            correct = correct && data.getTerminoMayor().equalsIgnoreCase(sylogism.getTerminoMayor());
            correct = correct && data.getTerminoMedio().equalsIgnoreCase(sylogism.getTerminoMedio());
            correct = correct && data.getTerminoMenor().equalsIgnoreCase(sylogism.getTerminoMenor());
            if (data.getPremisaMayorExtension() != null) {
                correct = correct && data.getPremisaMayorExtension().equals(
                        sylogism.getPremisa(PremisaTypeEnum.FIRST).getPartsExtension());
            } else {
                correct = false;
            }
            if (data.getPremisaMayorExtension() != null) {
                correct = correct && data.getPremisaMenorExtension().equals(
                        sylogism.getPremisa(PremisaTypeEnum.SECOND).getPartsExtension());
            } else {
                correct = false;
            }
            if (data.getPremisaMayorExtension() != null) {
                correct = correct && data.getConclusionExtension().equals(
                        sylogism.getPremisa(PremisaTypeEnum.CONCLUSION).getPartsExtension());
            } else {
                correct = false;
            }
            correct = correct && data.getFigura() == (sylogism.getFigure());
        } else {
            correct = false;
        }

        if (correct) {
            return getCorrectScore();
        } else {
            return getIncorrectScore();
        }
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.ANALIZAR_SILOGISMO.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]\n");
        buffer.append(getExcerciseData().toString() + "\n");//((Sylogism)getExcerciseData()).toString();
        return buffer.toString();
    }

    public String getStudentSolutionString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(
                        URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.ANALIZAR_SILOGISMO.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]\n");
        buffer.append("> " +
                BundlesProvider.getBundle(
                        URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.EXCERCISE.toString()) + ":\n");
        buffer.append(getExcerciseData().toString() + "\n");//((Sylogism)getExcerciseData()).toString();
        buffer.append("> " +
                BundlesProvider.getBundle(
                        URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.RESOLUCION.toString()) + ":\n");
        buffer.append(((SylogismData) getStudentsSolution()).toString());
        return buffer.toString();
    }
}
